package demo.view
{
	import data.app.DataController;
	import data.app.events.user.UserEvent;
	
	import demo.controller.DemoController;
	import demo.model.DemoModel;
	import demo.model.SceneModel;
	import demo.view.scene.SceneView;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import helper.StringHelper;
	
	import manager.MessageManager;
	
	public class DemoMain extends Sprite
	{
		private var _controller:DemoController;
		private var _model:DemoModel;
		private var _sceneModel:SceneModel;
		private var _sceneView:SceneView;
		
		public function DemoMain(controller:DemoController, model:DemoModel, sceneModel:SceneModel)
		{
			_controller=controller;
			_model=model;
			_sceneModel=sceneModel;
			initialize();
		}
		
		/**
		 * 初始化运行
		 */		
		private function initialize():void
		{
			setView();
			setEvent();
		}
		
		private function setView():void
		{
			_sceneView=new SceneView(_controller, _model, _sceneModel);
			addChild(_sceneView);
		}
		
		/**
		 *设置事件
		 */		
		private function setEvent():void
		{
			//			btnLogin.addEventListener(MouseEvent.CLICK, userLogin);
			DataController.Instance.dataReceive.userReceiveData.addEventListener(UserEvent.USER_LOGIN, userLoginReceive);
		}
		
		/**
		 *用户登陆 
		 */		
		private function userLogin(evt:MouseEvent):void
		{
			//			var userName:String=txtName.text;
			//			if(StringHelper.IsNullOrEmpty(userName))
			//			{
			//				MessageManager.Instance.sceneMessage("请输入昵称");
			//				return;
			//			}
			//			
			//			_controller.userLogin(userName);
		}
		
		private function userLoginReceive(evt:UserEvent):void
		{
			trace(evt.date);
		}
		
		public function show():void
		{
			if(!_controller.contains(this))
			{
				_controller.addChild(this);
			}
			if(!this.visible)
			{
				this.visible=true;
			}
		}
		
		public function hide():void
		{
			if(_controller.contains(this))
			{
				_controller.removeChild(this);
			}
		}
		
		public function dispose():void
		{
			_controller=null
			_model=null;
		}
	}
}